package model.events;

import javax.swing.event.EventListenerList;

public abstract class EntityEventEmitter
{
  private EventListenerList eventListeners = new EventListenerList();

  public void addEntityEventListener(EntityListener listener)
  {
    eventListeners.add(EntityListener.class, listener);
  }

  public void removeEntityEventListener(EntityListener listener)
  {
    eventListeners.remove(EntityListener.class, listener);
  }

  protected void fireAddedEvent(EntityEvent event)
  {
    for (EntityListener listener : eventListeners.getListeners(EntityListener.class))
      listener.entityAdded(event);
  }

  protected void fireModifiedEvent(EntityModifiedEvent event)
  {
    for (EntityListener listener : eventListeners.getListeners(EntityListener.class))
      listener.entityModified(event);
  }

  protected void fireMovedEvent(EntityEvent event)
  {
    for (EntityListener listener : eventListeners.getListeners(EntityListener.class))
      listener.entityMoved(event);
  }

  protected void fireRemovedEvent(EntityEvent event)
  {
    for (EntityListener listener : eventListeners.getListeners(EntityListener.class))
      listener.entityRemoved(event);
  }
}
